package Homework.cms.servlet;

import com.xcms.test.news.News;
import com.xcms.test.news.NewsDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class DelnewsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");     //告诉它当前文档的编码
        response.setHeader("Content-Type","text/html;utf-8");    //告诉浏览器文档类型
        String size=request.getParameter("size");
        //String id=request.getParameter("name");

        PrintWriter out=response.getWriter();   //获取一个打印流，向网页输出打印

        out.println(size);
        for(int i=0;i<Integer.parseInt(size);i++){
            String id=request.getParameter("name"+i);
            out.println(id);
        }

//        News news=new News();
//        news.setId(Integer.parseInt(id));
//
//        if(NewsDao.remove(news)){
//            out.println("alert(\"删除成功！\");");
//            response.setHeader("Refresh","3;url=http://localhost:8080/webtest/Homework/manage/news?action=page2&currPage=1");
//        }
//        else {
//            out.println("alert(\"删除失败！\");");
//        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
